﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RoleManagement.aspx.cs"
    Inherits="BEGDC.CC.Web.CIS2.Domestic.Admin.RoleManagement" %>

<%@ Import Namespace="System.Linq" %>
<%@ Import Namespace="ASBCC.Database.EntityFramework" %>
<%@ Register Src="../../../UserControls/Pager.ascx" TagName="Pager" TagPrefix="cc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="../../../css/global.css" rel="stylesheet" type="text/css" />
    <link href="../../../css/content/entity.css" rel="stylesheet" type="text/css" />
    <link href="../../../css/content/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
    <link href="../../../css/main.css" rel="stylesheet" type="text/css" />

    <script src="../../../js/jquery-1.4.4.min.js" type="text/javascript"></script>

    <script src="../../../js/jquery-ui.min.js" type="text/javascript"></script>

    <script src="../../../js/entity.js.aspx" type="text/javascript"></script>

    <script type="text/javascript">
        $(function() {

            $(".entity-belongsto").val($(".entity-belongsto").attr("u"));
        });
    </script>

    <style type="text/css">
        .muti-checkbox
        {
            float: left;
            width: 150px;
        }
    </style>
</head>
<body>
    <form runat="server">
    <asp:HiddenField ID="BelongsTo" Value="CID" runat="server" />
    <div class="mainbox">
        <div class="sitemapbox">
            <div id="info" class="sitemap">
                &nbsp;&raquo;&nbsp;Administration&nbsp;&raquo;&nbsp;Role Management
            </div>
        </div>
        <table cellspacing="0" cellpadding="0">
            <tr>
                <td>
                    <!--tab区域-->
                    <div class="tabbox purplebg_dark">
                        <ul class="tabpos">
                            <li><span class="tab_active">
                                <%=Resources.PageTitles.RoleManagement%></span></li>
                        </ul>
                    </div>
                    <div class="formbox">
                        <span class=" float_lft">
                            <div class="formbox_float_lft">
                                <asp:Button ID="BtnAdd" runat="server" CssClass="entity-add" />
                            </div>
                            <div class="formbox_float_rgt">
                                <asp:TextBox ID="SearchText" runat="server" CssClass="txtbox width140 entity-search-text"></asp:TextBox>
                                <asp:Button ID="Searchbtn" runat="server" CssClass="entity-search" />
                                <asp:Button ID="Cleanbtn" runat="server" CssClass="entity-clear" />
                            </div>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
        <table width="100%" id="Table1" cellspacing="0" cellpadding="0" border="0">
            <tbody>
                <tr>
                    <td>
                        <asp:GridView ID="GVRoles" runat="server" AutoGenerateColumns="False" DataKeyNames="RoleID"
                            DataSourceID="EntityRole" AllowSorting="True" AllowPaging="True" EmptyDataText="There is no data to display!"
                            CssClass="tablestyle">
                            <RowStyle CssClass="tbody" />
                            <HeaderStyle CssClass="thead" ForeColor="#ffffff" />
                            <Columns>
                                <asp:BoundField DataField="Name" HeaderText="Role Name<br/>角色名称" SortExpression="Name"
                                    HtmlEncode="false" />
                                <asp:BoundField DataField="Description" HeaderText="Comment<br/>备注" SortExpression="Description"
                                    HtmlEncode="false" />
                                <asp:BoundField DataField="BelongsTo" HeaderText="BelongsTo<br/>角色模块类属" SortExpression="BelongsTo"
                                    HtmlEncode="false" />
                                <asp:BoundField DataField="IsAdmin" HeaderText="IsAdmin<br/>是否是管理员角色" SortExpression="IsAdmin"
                                    HtmlEncode="false" />
                                <asp:ActionField HeaderText="Action<br />操作" HeaderStyle-CssClass="entity-action" ShowDisableButton="true"
                                    ShowModifyButton="true" ShowViewButton="true" />
                            </Columns>
                            <PagerTemplate>
                                <cc:Pager runat="server" />
                            </PagerTemplate>
                        </asp:GridView>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:DetailsView ID="DVRole" runat="server" AutoGenerateRows="False" DataKeyNames="RoleID"
                            DataSourceID="EntityRole" DefaultMode="Edit" Visible="false" CssClass="tablestyle2">
                            <HeaderStyle CssClass="tablestyle2_Title"></HeaderStyle>
                            <HeaderTemplate>
                                <%=Resources.PageTitles.RoleManagement%>
                            </HeaderTemplate>
                            <FieldHeaderStyle CssClass="tablestyle2_tdTitle" />
                            <Fields>
                                <asp:BoundField DataField="Name" HeaderText="Role Name (角色名称)" SortExpression="Name"
                                    ItemStyle-CssClass="entity-notnull-check" />
                                <asp:BoundField DataField="Description" HeaderText="Comment (备注)" SortExpression="Description" />
                                <asp:CheckBoxField DataField="IsAdmin" HeaderText="IsAdmin (是否是管理员)" SortExpression="IsAdmin" />
                                <asp:TemplateField ConvertEmptyStringToNull="False">
                                    <ItemTemplate>
                                        <asp:Repeater runat="server" DataSource='<%# from t in EvalX("AspxPages") as System.Collections.Generic.IEnumerable<AspxPage> where !t.Disabled select t %>'>
                                            <ItemTemplate>
                                                <div class="checkbox-class">
                                                    <%#Eval("FullName")%>
                                                </div>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:Repeater runat="server" DataSourceID="PageEditSource">
                                            <ItemTemplate>
                                                <input type="checkbox" name="pagecheck" value="<%# Eval("PageID") %>" <%#Eval("CanAccess") %> /><%# Eval("FullName") %>
                                                (<%# (ASBCC.Business.AccessLevel)Eval("AccessLevel")%>)<br />
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </EditItemTemplate>
                                    <HeaderTemplate>
                                        Page (页面)
                                    </HeaderTemplate>
                                    <InsertItemTemplate>
                                        <asp:Repeater runat="server" DataSourceID="PageEditSource">
                                            <ItemTemplate>
                                                <input type="checkbox" name="pagecheck" value="<%# Eval("PageID") %>" /><%# Eval("FullName") %>(<%# (ASBCC.Business.AccessLevel)Eval("AccessLevel")%>)<br />
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </InsertItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField ConvertEmptyStringToNull="False">
                                    <ItemTemplate>
                                        <asp:Repeater runat="server" DataSourceID="MenuEditSource">
                                            <ItemTemplate>
                                                <div class="checkbox-class">
                                                    <%#Eval("Name")%>
                                                    [
                                                    <%# Eval("Target")%>
                                                    ]<br />
                                                </div>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:Repeater runat="server" DataSourceID="MenuEditSource">
                                            <ItemTemplate>
                                                <%# Eval("Level")%><input type="<%#Eval("Disabled") %>" name="menucheck" value="<%# Eval("MenuID") %>"
                                                    <%#Eval("CanAccess") %> /><%# Eval("Name")%>
                                                [
                                                <%# Eval("Target")%>
                                                ]<br />
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </EditItemTemplate>
                                    <HeaderTemplate>
                                        Menu (菜单)
                                    </HeaderTemplate>
                                    <InsertItemTemplate>
                                        <asp:Repeater runat="server" DataSourceID="MenuEditSource">
                                            <ItemTemplate>
                                                <%# Eval("Level")%><input type="<%#Eval("Disabled") %>" name="menucheck" value="<%# Eval("MenuID") %>"></input><%# Eval("Name")%>
                                                [
                                                <%# Eval("Target")%>
                                                ]<br />
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </InsertItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField ConvertEmptyStringToNull="False" ItemStyle-CssClass="entity-checkboxes-check">
                                    <ItemTemplate>
                                        <asp:Repeater runat="server" DataSource='<%# GetPCAT(EvalX("PCATs")) %>'>
                                            <ItemTemplate>
                                                <div class="muti-checkbox">
                                                    <%#Eval("Province.Name")%><%#Eval("Category.Name")%>
                                                </div>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:Repeater runat="server" DataSourceID="PCatEditSource">
                                            <ItemTemplate>
                                                <div class="muti-checkbox">
                                                    <input type="checkbox" name="pcatcheck" value="<%# Eval("PCID") %>" <%#Eval("CanAccess") %> /><%# Eval("PName")%><%# Eval("CName")%></div>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </EditItemTemplate>
                                    <HeaderTemplate>
                                        PCAT (角色类属PCAT)
                                    </HeaderTemplate>
                                    <InsertItemTemplate>
                                        <asp:Repeater runat="server" DataSourceID="PCatEditSource">
                                            <ItemTemplate>
                                                <div class="muti-checkbox">
                                                    <input type="checkbox" name="pcatcheck" value="<%# Eval("PCID") %>" /><%# Eval("PName")%><%# Eval("CName")%></div>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </InsertItemTemplate>
                                </asp:TemplateField>
                                
                                <asp:TemplateField ConvertEmptyStringToNull="False" ItemStyle-CssClass="role-country">
                                    <ItemTemplate>
                                        <asp:Repeater runat="server" DataSource='<%# GetCountry(EvalX("Countries")) %>'>
                                            <ItemTemplate>
                                                <div class="muti-checkbox">
                                                    <%#Eval("Name")%>
                                                </div>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:Repeater ID="Repeater2" runat="server" DataSourceID="CountryEditSource">
                                            <ItemTemplate>
                                                <div class="muti-checkbox">
                                                    <input type="checkbox" name="countrycheck" value="<%# Eval("CountryID") %>" <%#Eval("CanAccess") %> /><%# Eval("Name")%></div>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </EditItemTemplate>
                                    <HeaderTemplate>
                                        Country (国家)
                                    </HeaderTemplate>
                                    <InsertItemTemplate>
                                        <asp:Repeater runat="server" DataSourceID="CountryEditSource">
                                            <ItemTemplate>
                                                <div class="muti-checkbox">
                                                    <input type="checkbox" name="countrycheck" value="<%# Eval("CountryID") %>" /><%# Eval("Name")%></div>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </InsertItemTemplate>
                                </asp:TemplateField>
                                <asp:ActionField ShowEditButton="true" ShowInsertButton="true" ShowInsertMoreButton="true"
                                    ShowCloseButton="true" />
                            </Fields>
                        </asp:DetailsView>
                        &nbsp;
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <%--以下是数据源--%>
    <asp:EntityDataSource ID="EntityRole" runat="server" ConnectionString="name=CCEntities"
        DefaultContainerName="CCEntities" EnableDelete="True" EnableInsert="True" EnableUpdate="True"
        EntitySetName="Roles" Where="it.BelongsTo='CID' and !it.Disabled" OnInserted="EntityRole_Inserted"
        OnUpdated="EntityRole_Updated" Include="AspxPages,Menus,PCATs,Countries">
    </asp:EntityDataSource>
    <asp:ObjectDataSource ID="PageEditSource" runat="server" SelectMethod="GetPagesByRoleID"
        TypeName="ASBCC.Business.RoleManagementHelper">
        <SelectParameters>
            <asp:ControlParameter ControlID="DVRole" Name="roleID" PropertyName="DataKey.Value"
                Type="Int32" />
            <asp:ControlParameter ControlID="BelongsTo" Name="belongsTo" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="MenuEditSource" runat="server" SelectMethod="GetMenusByRoleID"
        TypeName="ASBCC.Business.RoleManagementHelper">
        <SelectParameters>
            <asp:ControlParameter ControlID="DVRole" Name="roleID" PropertyName="DataKey.Value"
                Type="Int32" />
            <asp:ControlParameter ControlID="BelongsTo" Name="belongsTo" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="PCatEditSource" runat="server" SelectMethod="GetPCATsByRoleId"
        TypeName="ASBCC.Business.RoleManagementHelper">
        <SelectParameters>
            <asp:ControlParameter ControlID="DVRole" Name="roleID" PropertyName="DataKey.Value"
                Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="CountryEditSource" runat="server" SelectMethod="GetCountriesByRoleId"
        TypeName="ASBCC.Business.RoleManagementHelper">
        <SelectParameters>
            <asp:ControlParameter ControlID="DVRole" Name="roleID" PropertyName="DataKey.Value"
                Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>
    </form>
</body>
</html>
